#ifndef CONFIGMANAGER_H
#define CONFIGMANAGER_H

#include <QObject>
#include "singleton.h"
#include "systemconfig.h"
#include "configdefine.h"
#include <QMap>
#include <QMutex>

class ConfigManager : public QObject
{
    SINGLETON_DECLARE(ConfigManager)
public:
    ConfigManager(QObject *parent = nullptr);
    ~ConfigManager();

    bool get(ConfigKey key, QVariant &value);
    bool set(ConfigKey key, const QVariant &value);

    QVariant get(ConfigKey key);

    SystemConfig *m_systemConfig;

public slots:
    void onStart();

private:
    void loadAll();

    QString directory;

    /**
     * @brief m_configMap 共享的变量都在这里
     */
    QMap<ConfigKey, QVariant> m_configMap;
    QMutex m_mapMutex; // 共享的内容加锁
};

#define configManager ConfigManager::getInstance()

#endif // CONFIGMANAGER_H
